<template>
	<view class="content">
		<view class="newlist">
			<newList :list="newList" imgField="img_url" titleField="title" tipsField="tips" @handleClick="newItem"></newList>
		</view>
	</view>
</template>

<script>
	import newList from "../../components/new_list/index.vue";
	import {getNewList} from "../../static/js/api/user.js";
	export default {
		components:{
			newList
		},
		data(){
			return{
				newList:[],
				type:null,
			}
		},
		onLoad(option) {
			console.log(option)
			this.type = option.type
			// 1:咱们的咨询2；政策资讯
			this.getData()
			if(this.type=='1'){
				uni.setNavigationBarTitle({
					title:'奥北资讯'
				})
			}else{
				uni.setNavigationBarTitle({
					title:'体育政策资讯'
				})
			}
		},
		methods:{
			getData(){
				this.newList = []
				getNewList({
					page:1,
					type:this.type
				}).then(res=>{
					console.log(res)
					if(res.news){
						res.news.forEach(item=>{
							if(item.author){
								item.tips = '作者：'+item.author
							}
							if(item.type==this.type){
								this.newList.push(item)
							}
						})
						
					}
				})
			},
			newItem(item){
				if(this.type==1){
					for (let i = 0; i < item.content.length; i++) {
						if (item.content[i] == '&') {
							item.content = item.content.replace('&', '!')
						}
					}
					console.log(item.content)
					let info = {
						img_url: item.img_url,
						title: item.title,
						content: item.content,
						author: item.author,
						id: item.id,
					}
					uni.navigateTo({
						url: "/pages/campus/listDetails?newInfo=" + JSON.stringify(info)
					})
				}else{
					// var startSpan = item.content.indexOf("<p>");
					// var endSpan = item.content.indexOf("</p>");
					// let url = item.content.slice(startSpan+3,endSpan)
					uni.navigateTo({
						url:'/pages/home/about?url='+item.content
					})
				}
			},
		}
	}
</script>

<style lang="scss" scoped>
	.content{
		padding-bottom: constant(safe-area-inset-bottom);
		padding-bottom: env(safe-area-inset-bottom);
		.newlist{
			background-color: #ffffff;
		}
	}
</style>